package cn.lg.soar.system.biz.modules.message.client;

import cn.lg.soar.core.annotations.ApiClient;
import cn.lg.soar.system.api.constant.ModuleConst;
import cn.lg.soar.system.api.model.NoticeDTO;
import cn.lg.soar.system.api.service.INoticeApi;
import cn.lg.soar.system.biz.modules.message.entity.Notice;
import cn.lg.soar.system.biz.modules.message.service.INoticeService;
import io.swagger.v3.oas.annotations.Hidden;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author luguoxiang
 * @date 2022/1/3
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Hidden
@ApiClient("boot")
@RestController
@RequestMapping(ModuleConst.CLIENT_PATH + "/notice")
public class NoticeApiClient implements INoticeApi {

    @Autowired
    private INoticeService service;

    @PostMapping("broadcast")
    @Override
    public void broadcast(@RequestBody NoticeDTO dto) {
        Notice notice = toEntity(dto);
        service.broadcast(notice);
    }

    @PostMapping("toUser")
    @Override
    public void toUser(NoticeDTO dto, @RequestBody List<Long> userIds) {
        Notice notice = toEntity(dto);
        service.toUser(notice, userIds);
    }

    private Notice toEntity(NoticeDTO dto) {
        Notice notice = new Notice();
        BeanUtils.copyProperties(dto, notice);
        return notice;
    }
}
